package com.alpha.eceasy.mall.service.impl;

import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONUtil;
import com.alpha.eceasy.core.R;
import com.alpha.eceasy.mall.client.CommunicationRecordDTO;
import com.alpha.eceasy.mall.client.DemandContactCommunicationRecordResponseDTO;
import com.alpha.eceasy.mall.client.ResponseData;
import com.alpha.eceasy.mall.client.UserRequestClient;
import com.alpha.eceasy.mall.service.DemandContactCommunicationRecordService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (DemandContactCommunicationRecord)表服务实现类
 *
 * @author makejava
 * @since 2024-03-15 18:00:45
 */
@Service("demandContactCommunicationRecordService")
@Slf4j
@Deprecated
public class DemandContactCommunicationRecordServiceImpl implements DemandContactCommunicationRecordService {

    @Resource
    private UserRequestClient userRequestClient;

    @Override
    public R create(CommunicationRecordDTO requestVo) {
        log.info("requestVo:{}", requestVo);
        String uuid= IdUtil.simpleUUID();
        requestVo.setGuid(uuid);
        ResponseData insert = userRequestClient.insert(requestVo);
        if (insert.isSuccess()) {
            if (insert.getData()!=null){
                return R.ok("添加成功");
            }

        }

        return R.failed("添加失败");
    }

    @Override
    public R pageList(String orderAliasId) {
        ResponseData r = userRequestClient.pageList(orderAliasId);
        List<DemandContactCommunicationRecordResponseDTO> demandContactCommunicationRecordResponseDTOS = null;
        if (r.isSuccess()) {
            if (r.getData() != null) {
                String jsonString = JSONUtil.toJsonStr(r.getData());
                demandContactCommunicationRecordResponseDTOS = JSONUtil.toList(jsonString, DemandContactCommunicationRecordResponseDTO.class);
                log.info("demandContactCommunicationRecordResponseDTOS:{}",demandContactCommunicationRecordResponseDTOS);
                return R.ok(demandContactCommunicationRecordResponseDTOS);
            }
        }
        return R.failed("查询失败");
    }

    @Override
    public R getBriefInfo(String demandContactGuid) {
        return R.ok(userRequestClient.getBriefInfo(demandContactGuid).getData());
    }
}

